﻿#pragma once

//////////////////////////////////////////////////////////////////////////
// structures and definition used by export XiAn customised bmp file [12/12/2016 ejitec]

#pragma pack(push)
#pragma pack(1)

typedef struct XiAnHead
{
	unsigned short szHead[8];

	XiAnHead()
	{
		for (int i = 0; i < 8; i++)
		{
			szHead[i] = (0xff - i) << 8 | i;
		}
	}

	bool operator==(const XiAnHead& other)
	{
		bool bTheSame = true;
		for (int i = 0; i < 8; i++)
		{
			if (szHead[i] != other.szHead[i])
			{
				bTheSame = false;
				break;
			}
		}

		return bTheSame;
	}

}TXiAnHead;

typedef struct XiAnData
{
	TXiAnHead m_tHead;  // 0-15
	char m_cCamNo;   // 16
	char m_cDepth;   // 17
	int m_nFramIndex;  //18-21
	unsigned short m_sRows;  // 22-23
	unsigned short m_sCols;  // 24-25
	unsigned short m_sFps;   // 26-27
	unsigned short m_sMilSec;  // 82-29
	unsigned char m_cSec;  //30
	unsigned char m_cMinute;  //31
	unsigned char m_cHour; //32
	unsigned char m_szExcpetion[4]; // 33-36
#if (defined(XIANGS_VERSION) && XIANGS_VERSION == 1)
	unsigned char m_szUdpGps[8];        //37-44 时间码，单位：ms 4字节无符号整形，低位在前  
	unsigned char m_szUdpSingle[32];   //45-76 第31、32字节（焦距值*10）
	unsigned char m_szUdpMuti_1[24];  //77-100    164 -- 195   从第189字节开始，连续8个字节（4字节方位角，4字节俯仰角）
	unsigned char m_szTime[3];  //101-103
	unsigned char m_szUdpMuti_2[8]; // 104-111
#else
	unsigned char m_szUdp4_deserve[64];
	unsigned char m_szTime[3];  //101-103
	unsigned char m_szUdp1_tm[4];
	unsigned char m_szUdp2_Aangle[40];
	unsigned char m_szUdp2_Eangle[40];
	unsigned char m_szUdp3_unused1[4];
	unsigned char m_szUdp3_status[4];
	unsigned char m_szUdp3_focal[4];
	unsigned char m_szUdp3_distance[4];
	unsigned char m_szUdp3_fraps[4];
	unsigned char m_szUdp3_exposureTm[4];
	unsigned char m_szUdp3_deserve[31];
	unsigned char m_szUdp3_unused2[9];

#endif

}XIAN_GS_DATA;


typedef struct tagXIAN_DisPlay_DATA
{
	unsigned long current_time;
	float azimuth_angle;
	float pitch_angle;
	unsigned long focal_len;
	unsigned long fraps;
	unsigned long distance;

	tagXIAN_DisPlay_DATA()
	{
		current_time = 0;
		azimuth_angle = 0;
		pitch_angle = 0;
		focal_len = 0;
		distance = 0;
		fraps = 0;
	}

	//  显示时 不再循环转换
	void setData(XIAN_GS_DATA* pData, int nPos = 0)
	{
#if (defined(XIANGS_VERSION) && XIANGS_VERSION == 1)

		unsigned long mutilHead = 0xAA55feff, mutilHeadRcv = 0;
		memcpy(&current_time, pData->m_szUdpGps + 1, 4);
		current_time *= 10;
		memcpy(&mutilHeadRcv, pData->m_szUdpMuti_1, 4);
		if (mutilHead == mutilHeadRcv)
		{
			memcpy(&azimuth_angle, pData->m_szUdpMuti_1 + 12, 4);
			memcpy(&pitch_angle, pData->m_szUdpMuti_1 + 16, 4);
		}
		unsigned short fLen = 0;
		// 焦距2个字节无法存浮点
		memcpy(&fLen, pData->m_szUdpSingle + 30, 2);
		focal_len = fLen;
#else
		if (nPos > 10 || nPos < 0)
		{
			nPos = 0;
		}
		long A = .0, E = .0;
		memcpy(&current_time, pData->m_szUdp1_tm, 4);
		current_time *= 10;
		memcpy(&A, pData->m_szUdp2_Aangle + 4 * nPos, 4);
		memcpy(&E, pData->m_szUdp2_Eangle + 4 * nPos, 4);
		azimuth_angle = A * 360.0 / 0x80000000;
		pitch_angle = E * 360.0 / 0x80000000;
		memcpy(&focal_len, pData->m_szUdp3_focal, 4);
		memcpy(&fraps, pData->m_szUdp3_fraps, 4);
		memcpy(&distance, pData->m_szUdp3_distance, 4);
#endif

	}

}XIAN_DisPlay_DATA;


#pragma pack(pop)